﻿using DomainModel;
using FluentNHibernate.Mapping;

namespace Repository.NHibernate.Mapping
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Id(x => x.Id).GeneratedBy.Native();
            Map(x => x.Login);
            Map(x => x.PasswordHash);
            Map(x => x.Email);
            Map(x => x.IsApproved);
            Component<Profile>(x => x.Profile, p =>
                                                   {
                                                       p.Map(x => x.FirstName);
                                                       p.Map(x => x.LastName);
                                                       p.Map(x => x.Phone);
                                                       p.Map(x => x.PhotoUrl);
                                                   }).LazyLoad();
            References<Group>(x => x.Group);
            References<Subgroup>(x => x.Subgroup);
            References<User>(x => x.Child);
            HasMany<Role>(x => x.Roles).Element("RoleValue");
        }
    }
}